<template>
  <base-breadcrumb>
    <searchData :search-data="searchArr" @search="search" />
    <a-card>
      <div class="pub-table-select-count">
        <a-icon type="info-circle" theme="twoTone" />
        <span style="margin-right: 12px"> 安全验收计划项总数：
          <span class="totalNum">{{ totalDetails.total }}</span> 个  |
          计划内未提交： <span class="totalNum">{{ totalDetails.inDraft }}</span> 个  |
          计划内已提交 <span class="totalNum">{{ totalDetails.inSubmitted }}</span> 个
          计划外已提交 <span class="totalNum">{{ totalDetails.outSubmitted }}</span> 个
        </span>
      </div>
      <!-- 统计 -->
      <list-table
        ref="table"
        size="default"
        row-key="id"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        show-pagination="auto"
      >
        <template slot="action" slot-scope="text, record">
          <div class="pub-table-list-action">
            <span v-btn-permission="'hse_020_loo_04'" @click="$nav('acceptanceRecordDetail',{id:record.id})">查看</span>
            <span v-btn-permission="'hse_020_del_03'" @click="del(record.id)" v-if="hideBuquBtn()">删除</span>
          </div>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>
<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import SelectSubcontractor from '@/components/Select/SelectSubcontractor' // 分包商
import SelectAcceptanceType from '@/components/Select/SelectAcceptanceType' // 验收分类
import BasePrintButton from '@/components/BasePrintButton' // 打印按钮
import {
  getAcceptanceRecordList,
  getAcceptanceRecordCount,
  getPrintContent, del
} from '@/api/safetySupervision/acceptancePlan'
import { STable } from '@/components'

export default {
  name: 'a' + Date.now(),
  components: {
    STable,
    BasePrintButton
  },
  data() {
    return {
      columns: [
        { title: '验收部位', dataIndex: 'acceptPart', width: 150 },
        { title: '验收类型', dataIndex: 'planTypeStr', width: 150 },
        { title: '验收分类', dataIndex: 'acceptClassificat', width: 200 },
        { title: '所属分公司', dataIndex: 'branchComName', width: 150 },
        { title: '所属项目', dataIndex: 'projectName', width: 250 },
        { title: '计划时间', dataIndex: 'plannTime', width: 150 },
        { title: '实际时间', dataIndex: 'realTime', width: 150 },
        { title: '分包单位名称', dataIndex: 'subcontractorName', width: 200 },
        { title: '验收负责人', dataIndex: 'acceptPerson', width: 150 },
        { title: '填报人', dataIndex: 'creatorName', width: 150 },
        { title: '填报时间', dataIndex: 'createTime', width: 150 },
        { title: '验收结果', dataIndex: 'resultStr', },
        {
          title: '操作',
          dataIndex: 'action',
          width: 180,
          fixed: 'right',
          scopedSlots: { customRender: 'action' }
        }
      ],
      searchArr: [
        {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
        // { name: '所属分公司', valueKey: 'branchComId', type: SelectSubCompany },
        // { name: '所属项目', keyValue: 'branchComId', valueKey: 'projectId', type: SelectProject },
        { name: '分包单位', value: 'subcontractorName', type: 'input' },
        { name: '验收分类', valueKey: 'acceptCategoryId', type: SelectAcceptanceType },
        { name: '验收部位', value: 'acceptLocation', type: 'input' },
        {
          name: '验收类型', value: 'planType', type: 'select', data: [
            { value: 0, label: '计划内' },
            { value: 1, label: '计划外' }
          ]
        },
        { name: '填报人', value: 'creatorName', type: 'input' },
        { name: '填报时间', value: 'applyTime', type: 'dateRange' }
      ],
      queryParam: {},
      totalDetails: {
        total: 0,
        draft: 0,
        submitted: 0,
        past: 0,
        rejected: 0
      },
      loadData: async (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        this.getAcceptanceRecordCount(this.queryParam)
        const [err, res] = await getAcceptanceRecordList(requestParameters)
        return new Promise((resolve, reject) => {
          if (err) {
            reject(err)
          } else {
            resolve(res)
          }
        })
      }
    }
  },
  computed: {
    applyed() {
      return this.totalDetails.past + this.totalDetails.rejected
    },
    submited() {
      return this.totalDetails.submitted + this.totalDetails.past + this.totalDetails.rejected
    },
    noSubmit() {
      return this.totalDetails.total - this.submited
    }
  },
  methods: {
    //搜索
    search(val = {}) {
      this.queryParam = {
        ...val,
        hsemonth: (val.acceptMonth && val.acceptMonth.format('YYYY-MM')) || void 0,
        createTimeBegin:
          (val.applyTime && val.applyTime.length && val.applyTime[0].format('YYYY-MM-DD')) || void 0,
        createTimeEnd:
          (val.applyTime && val.applyTime.length && val.applyTime[1].format('YYYY-MM-DD')) || void 0
      }
      delete this.queryParam.acceptMonth
      this.$refs.table.refresh(true)
    },
    // 统计
    async getAcceptanceRecordCount(param) {
      const [err, res] = await getAcceptanceRecordCount(param)
      if (!err) {
        this.totalDetails = res.data
      }
    },
    del(id) {
      this.$delList3(del, () => {
        this.$refs.table.refresh(true)
      }, { id })
    }
  }
}
</script>
